package com.aijk.ehm.service;

import com.aijk.base.entity.PagingRequest;
import com.aijk.commons.utils.Utils;

import com.aijk.ehm.dao.mybatis.SemBpMapper;
import com.aijk.ehm.model.SemBp;
import com.aijk.ehm.model.SemBpExample;
import com.aijk.ehm.model.qo.SemBpQo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 检测指标_血压
 */
@Service
public class SemBpService {
    private static Logger logger = LoggerFactory.getLogger(SemBpService.class);

    @Autowired
    private SemBpMapper mapper;

    public SemBpExample getExample(SemBpQo qo) {
        SemBpExample example = new SemBpExample();
        SemBpExample.Criteria criteria = example.createCriteria();
        if (qo != null) {
            if (Utils.isNotEmpty(qo.getSortway())) example.setOrderByClause(qo.getSortway());
            if (qo.getResidentId()!= null) criteria.andResidentIdEqualTo(qo.getResidentId());
            if (qo.getUid()!= null) criteria.andUidEqualTo(qo.getUid());
            if (qo.getIdcard()!= null) criteria.andIdcardEqualTo(qo.getIdcard());
            if (qo.getDevicesn()!= null && qo.getDevicesn()!="") criteria.andDevicesnEqualTo(qo.getDevicesn());
        }
        return example;
    }

    public int count(SemBpQo qo) {
        return mapper.countByExample(getExample(qo));
    }

    public int save(SemBp bean) {
        return mapper.insertSelective(bean);
    }

    public int delete(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    public int update(SemBp bean) {
        return mapper.updateByPrimaryKeySelective(bean);
    }

    public SemBp findOne(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<SemBp> find(SemBpQo qo) {
        return mapper.selectByExample(getExample(qo));
    }

    public PageInfo<SemBp> page(PagingRequest pagingRequest, SemBpQo qo) {
        PageHelper.startPage(pagingRequest.getPageNum() , pagingRequest.getPageSize());
        return new PageInfo<SemBp>(mapper.selectByExample(getExample(qo)));
    }
}